package com.samebuilding.service.impl;

import org.springframework.core.task.TaskExecutor;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

public class MailServer {
	private MailSender mailSender;

	public MailSender getMailSender() {
		return mailSender;
	}

	public void setMailSender(MailSender mailSender) {
		this.mailSender = mailSender;
	}

	private class SendMail implements Runnable {

		private SimpleMailMessage mail;

		public SendMail(SimpleMailMessage mail) {
			this.mail = mail;
		}

		public void run() {
			mailSender.send(mail);
		}

	}

	private TaskExecutor taskExecutor;

	public MailServer(TaskExecutor taskExecutor) {
		this.taskExecutor = taskExecutor;
	}

	public void sendMail(SimpleMailMessage message) {
		this.taskExecutor.execute(new SendMail(message));
	}
	
}
